package com.lankystar.logistucs.spring.service.impl;


import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lankystar.logistucs.spring.dao.ICompanyDao;
import com.lankystar.logistucs.spring.dao.ITruckStatusDao;
import com.lankystar.logistucs.spring.dao.IUserDao;
import com.lankystar.logistucs.spring.dao.IUserTypeDao;
import com.lankystar.logistucs.spring.entity.Company;
import com.lankystar.logistucs.spring.entity.TruckStatus;
import com.lankystar.logistucs.spring.entity.User;
import com.lankystar.logistucs.spring.entity.UserType;
import com.lankystar.logistucs.spring.service.UserService;
import com.syx.spring.utils.StringHandler;

@Service
public class UserServiceImpl implements UserService{

	@Autowired
	private IUserDao userDao;
	@Autowired
	private IUserTypeDao userTypeDao;
	@Autowired
	private ITruckStatusDao truckStatusDao;
	@Autowired
	private ICompanyDao companyDao;
	@Override
	public void addUser(User record) {
			userDao.add(record);
	}
	
	@Override
	public User login(String userPhone, String userPassword) {
		User user = userDao.selectUserByUserPhoneAndUserPassword(userPhone, userPassword);
		
		return user;
	}

	@Override
	public void updateUser(User record) {
		User user = userDao.selectUserById(record.getUserId());
		/**
		 * 用户类型无法修改
		 */
		user.setUserName(record.getUserName());
		user.setUserName(record.getUserPhone());
		user.setUserName(record.getUserPassword());
		if(record.getDrivLicence()!=null){
			user.setUserName(record.getDrivLicence());
		}
		userDao.update(user);
		
	}

	@Override
	public List<User> queryUserlist(UserType userType) {
		List<User> userlist = userDao.selectUserlist((userType.getUserKey()*10000)+1);
		return userlist;
	}

	@Override
	public void deleteUser(Integer ismove, Integer isusual,Integer userId) {
		User user = userDao.selectUserById(userId);
		/**
		 * 用户删除、禁用、启用
		 */
		if(ismove!=null&&ismove.equals(0)){
			user.setRemove(1);
			userDao.update(user);
		}
		if(isusual!=null&&isusual.equals(1)){
			user.setUsual(1);
			userDao.update(user);
		}else if(isusual!=null&&isusual.equals(0)){
			user.setUsual(0);
			userDao.update(user);
		}
		
	}

	@Override
	public User selectUserById(Integer userId) {
		User user = userDao.selectUserById(userId);
		return user;
	}

	@Override
	public List<User> queryCanUserlist() {
		List<User> userlist = userDao.selectCanUserlist();
		return userlist;
	}

}
